/* poj1743
 *
 * 大意是找不可重叠最长重复子串，不过要对题意进行一些转换。
 *
 * 这里将suffix_array用vector封装，使得串里的数可以是负数。
 * 对于这个版本代码还要进行理解，主要是关于末尾需不需再要加最小数的问题。
 *
*/

#include <cstdio>
#include <vector>
#include <algorithm>

struct suffix_array
{
	typedef std::vector<int> & v_ref;
	typedef std::vector<int> const & v_cref;

	struct suffix_cmp
	{
		suffix_cmp(v_cref rank, int const & gap, int const & len)
			: rank(rank), gap(gap), len(len) {}

		bool operator()(int i, int j)
		{
			if (rank[i] != rank[j]) return rank[i] < rank[j];
			return (i + gap < len && j + gap < len) ?
						(rank[i + gap] < rank[j + gap]) : i > j;
		}

	private:
		v_cref rank;
		int const & gap;
		int const & len;
	};

	suffix_array(v_cref s, int n, v_ref sa, v_ref rank, v_ref height)
		: s(s), n(n), sa(sa), rank(rank), height(height)
	{
		tmp_rank.resize(n);
	}

	void build_suffix_array()
	{
		for (int i = 0; i < n; i++) { sa[i] = i; rank[i] = s[i]; }
		for (int gap = 1; ; gap *= 2) {
			suffix_cmp cmp(rank, gap, n);
			std::sort(sa.begin(), sa.begin() + n, cmp);
			for (int i = 0; i < n-1; i++)
				tmp_rank[i + 1] = tmp_rank[i] + cmp(sa[i], sa[i + 1]);
			for (int i = 0; i < n; i++) rank[sa[i]] = tmp_rank[i];
			if (tmp_rank[n - 1] == n - 1) break;
		}
	}

	void build_lcp()
	{
		for (int i = 0, k = 0; i < n; i++)
			if (rank[i] != n-1) {
				for (int j = sa[rank[i] + 1]; s[i + k] == s[j + k]; k++);
				height[rank[i]] = k;
				if (k) k--;
			}
	}

private:
	v_cref s;
	int n;
	v_ref sa; // suffix array
	v_ref rank;
	v_ref height; // lcp array, longest common prefix array
	std::vector<int> tmp_rank;
};

int const maxn = 20017;
std::vector<int> sa(maxn);
std::vector<int> rank(maxn);
std::vector<int> height(maxn);
std::vector<int> da(maxn);
int n;

bool judge(int len)
{
	int min = sa[0], max = sa[0];
	for (int i = 0; i < n - 1; i++) {
		if (height[i] < len) {
			if (max - min > len) return true;
			max = sa[i + 1]; min = sa[i + 1];
		} else {
			max = std::max(max, sa[i + 1]);
			min = std::min(min, sa[i + 1]);
		}
	}
	return max - min > len;
}

int main()
{
	for (int first; std::scanf("%d", &n) && n; ) {
		std::scanf("%d", &first);
		if (n == 1) { std::printf("0\n"); continue; }
		for (int i = 1, tmp; i < n; i++) {
			std::scanf("%d", &tmp);
			da[i-1] = tmp - first;
			first = tmp;
		}

		suffix_array suffix(da, n-1, sa, rank, height);
		suffix.build_suffix_array();
		suffix.build_lcp();

		int l = 1, r = n-1;
		while (l + 1 < r) {
			int mid = (l + r) / 2;
			if (judge(mid)) l = mid;
			else			r = mid - 1;
		}
		if (judge(r)) l = r;
		int ans = l + 1;

		if (ans < 5) ans = 0;
		std::printf("%d\n", ans);
	}
}

